package com.twang.stock.controller.common;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.twang.stock.entity.CompanyCodeInfo;
import com.twang.stock.service.CompanyStockMinutesService;
import com.twang.stock.service.jinyan.CompanyCodeInfoService;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.util.List;

/**
 * 自选
 */
@Controller
@RequestMapping(value = "/")
@Slf4j
public class StockMinutesController {


    @Autowired
    private CompanyStockMinutesService companyStockMinutesService;
    @Autowired
    private CompanyCodeInfoService companyCodeInfoService;

    @RequestMapping(value = "/stockMinutes")
    public ModelAndView zhangTingBan(String code) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        if(StringUtils.isEmpty(code)){
            throw new Exception("字段不能为空！");
        }
        code=code.replace("name_","").trim();
        CompanyCodeInfo companyCodeInfo=companyCodeInfoService.getInfoByStockName(code);
        //
        List<String> days = Lists.newArrayList();
        List<BigDecimal> vols = companyStockMinutesService.getMaxTradeMinutesVol(code,days);

        /**
         * 返回
         */
        modelAndView.addObject("companyCodeInfo",companyCodeInfo);
        modelAndView.addObject("days",days);
        modelAndView.addObject("vols",vols);
        modelAndView.setViewName("line-simple");
        return modelAndView;
    }

    @RequestMapping(value = "/stockMinutes30")
    public ModelAndView stockMinutes30(String code) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        if(StringUtils.isEmpty(code)){
            throw new Exception("字段不能为空！");
        }
        code=code.replace("name_","").replace("sh","").replace("sz","").trim();
        CompanyCodeInfo companyCodeInfo=companyCodeInfoService.getInfoByStockName(code);
        //
        List<String> days = Lists.newArrayList();
        List<BigDecimal> vols = companyStockMinutesService.getTrade30MinutesVol(code,days);

        /**
         * 返回
         */
        modelAndView.addObject("companyCodeInfo",companyCodeInfo);
        modelAndView.addObject("days",days);
        modelAndView.addObject("vols",vols);
        modelAndView.setViewName("line-simple");
        return modelAndView;
    }

}
